package exercise;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @classname:demo01
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/11 11:42
 * @version: 0.1
 * @since:1.8
 */
public class CollectionDemo {
    public static void main(String[] args) {
        demo01();//add,remove,循环
    }

    private static void demo01() {
        Collection<String> collection = new ArrayList<>();
        collection.add("a");
        collection.add("jim");
        collection.add(null);
        collection.add("jim");
        collection.add("jim1");
        collection.add("jim2");


//        System.out.println(collection.isEmpty());
//        System.out.println(collection.contains("jim2"));
//        Object[] objects = collection.toArray();

//        String[] strings = collection.toArray(new String[0]);
//        System.out.println(Arrays.toString(strings));
//

//        collection.removeIf(new Predicate<String>() {
//            @Override
//            public boolean test(String s) {
//                return "jim".equals(s);
//            }
//        });
//        collection.forEach(System.out::print);
//        collection.removeIf(s -> "jim".equals(s));
//        System.out.println();
//        collection.forEach(System.out::print);

        Iterator<String> iterator = collection.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
    }
}
